home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / CHIPCD_02_2002.iso / Internet / Macromedia ColdFusion Server 5 / coldfusion-50-win-us.exe / data1.cab / Examples / CFDOCS / snippets / cfinsert.cfm < prev    next >
Encoding:
Text File  |  2001-06-13  |  2.5 KB  |  80 lines

  1. <!--- This example shows how to use CFINSERT instead of CFQUERY
  2. to place data into a datasource. --->
  3.  
  4.  
  5. <!--- if form.POSTED exists, we are inserting a new record,
  6. so begin the CFINSERT tag --->
  7. <!--- Under UNIX you must add CommentID to the FORMFIELDS --->
  8. <!---<CFIF IsDefined ("form.posted")>
  9.   <CFIF Server.OS.Name IS "Windows NT">
  10.     <CFINSERT DATASOURCE="cfsnippets"
  11.       TABLENAME="Comments"
  12.       FORMFIELDS="EMail,FromUser,Subject,MessText,Posted">
  13.   <CFELSE>
  14.       <CFINSERT DATASOURCE="cfsnippets"
  15.       TABLENAME="Comments"
  16.       FORMFIELDS="CommentID,EMail,FromUser,Subject,MessText,Posted">
  17.   </CFIF>
  18. <H3><I>Your record was added to the database.</I></H3>
  19. </CFIF>
  20.  
  21. <!--- use a query to show the existing state of the database --->
  22. <CFQUERY NAME="GetComments" DATASOURCE="cfsnippets">
  23. SELECT     CommentID, EMail, FromUser, Subject, CommtType, MessText, Posted, Processed
  24. FROM       Comments
  25. </CFQUERY> --->
  26.  
  27. <HTML>
  28. <HEAD>
  29. <TITLE>CFINSERT Example</TITLE>
  30. </HEAD>
  31.  
  32. <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  33.  
  34. <BODY  bgcolor="#FFFFD5">
  35. <H3>CFINSERT Example</H3>
  36. This is a read-only example. Because database access
  37. is a sensitive area, consider the security of your database before 
  38. allowing people to insert, update, or delete data from it.
  39.  
  40. <P>First, we'll show a list of the available comments in the cfsnippets datasource.
  41.  
  42. <!--- show all the comments in the db --->
  43. <!---<TABLE>
  44.     <TR>
  45.         <TD>From User</TD><TD>Subject</TD><TD>Comment Type</TD><TD>Message</TD><TD>Date Posted</TD>
  46.     </TR>
  47. <CFOUTPUT query="GetComments">
  48.     <TR>
  49.         <TD valign=top><a href="mailto:#EMail#">#FromUser#</A></TD>
  50.         <TD valign=top>#Subject#</TD>
  51.         <TD valign=top>#CommtType#</TD>
  52.         <TD valign=top><FONT SIZE="-2">#Left(MessText, 125)#</FONT></TD>
  53.         <TD valign=top>#Posted#</TD>
  54.     </TR>
  55. </CFOUTPUT>
  56. </TABLE>
  57.  
  58. <P>Next, we'll offer the opportunity to enter your own comment:
  59.  
  60. <!--- make a form for input --->
  61. <FORM ACTION="cfinsert.cfm" METHOD="POST">
  62. <!--- dynamically determine today's date --->
  63. <INPUT TYPE="Hidden" NAME="posted" VALUE="<CFOUTPUT>#Now()#</CFOUTPUT>">
  64. <PRE>
  65. Email:    <INPUT TYPE="Text" NAME="EMail">
  66. From:    <INPUT TYPE="Text" NAME="FromUser">
  67. Subject:<INPUT TYPE="Text" NAME="Subject">
  68. Message:<TEXTAREA NAME="MessText" COLS="40" ROWS="6"></TEXTAREA>
  69.  
  70. Date Posted:    <CFOUTPUT>#DateFormat(Now())#</CFOUTPUT>
  71. </PRE>
  72. <BR>
  73. Comment ID <B>(UNIX server only)</B>:    <INPUT TYPE="Text" NAME="CommentID">
  74. <P>
  75. <INPUT TYPE="Submit" VALUE="Insert My Comment">
  76. </FORM> 
  77.  --->
  78. </BODY>
  79. </HTML>       
  80.